home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
graphics
/
h8jpg
/
src
/
h8jpg.s
< prev
next >
Wrap
Text File
|
1999-05-25
|
16KB
|
830 lines
;
;
; h8jpg - High-Quality-HAM8 JPEG image viewer
;
; code by Smack/Infect!
;
;
; requirements:
; -AGA, MC68020+, OS V39+
; -jpeg.library V5+
; -reqtools.library V38+
;
;
; Tue 18-May-99 V0.1
;
;
incdir hd2:h8jpg/src/
include os_macros.i
section code,code
first_
basereg first_,a4
lea (first_,pc),a4
;--------------------------------------
; libraries
move.l (4).w,a6
move.l (378,a6),a0 ;LibList
lea (intuitionname,pc),a1
CALL FindName
move.l d0,(intuitionbase,a4)
move.l (378,a6),a0 ;LibList
lea (gfxname,pc),a1
CALL FindName
move.l d0,(gfxbase,a4)
move.l (378,a6),a0 ;LibList
lea (dosname,pc),a1
CALL FindName
move.l d0,(dosbase,a4)
move.l d0,a6
;--------------------------------------
; check system requirements
move.l (4).w,a5
cmp #39,(20,a5) ;LIB_Version
blt err_ende
lea (titletxt,pc),a0
move.l a0,d1
CALL PutStr
move (296,a5),d0 ;AttnFlags
and #2,d0
beq.b .syserr
move.l (gfxbase,pc),a0
move.b (236,a0),d0 ;gb_ChipRevBits0
and.b #$0c,d0 ;GFXF_AA_Alice | GFXF_AA_Lisa
bne.b .sysok
.syserr
lea (syserrtxt,pc),a0
move.l a0,d1
CALL PutStr
bra err_ende
.sysok
;--------------------------------------
; jpeg library
moveq #5,d0
lea (jpegname,pc),a1
CALLEXEC OpenLibrary
move.l d0,(jpegbase,a4)
bne.b .jpeglib_ok
lea (jpegliberrtxt,pc),a0
move.l a0,d1
CALLDOS PutStr
bra err_ende
.jpeglib_ok
;--------------------------------------
; read command line arguments
lea (template,pc),a0
move.l a0,d1
lea (readargs_result,pc),a0
move.l a0,d2
moveq #0,d3
CALLDOS ReadArgs
move.l d0,(rdargs,a4)
move.l (readargs_result,pc),(filenames_array,a4)
bne filenames_ok
;--------------------------------------
; no filenames given
moveq #38,d0
lea (rtname,pc),a1
CALLEXEC OpenLibrary ;V38 reqtools.library
move.l d0,(rtbase,a4)
beq ende
moveq #0,d0 ;RT_FILEREQ
lea (tags_tagdone,pc),a0
CALLRT rtAllocRequestA
move.l d0,(filerequest,a4)
beq err_ende
dofilerequester
lea (filereqtags,pc),a0
move.l (filerequest,pc),a1
lea (rtfilename,pc),a2
lea (filereqtitle,pc),a3
CALLRT rtFileRequestA
move.l d0,(rtfilelist,a4)
beq ende
move.l d0,(rtfilelist_curr,a4)
move.l (filerequest,pc),a5
move.l (16,a5),d1 ;filereq->dir
beq.b .no_currdir_new
moveq #-2,d2 ;SHARED_LOCK
CALLDOS Lock
move.l d0,d1
beq err_ende
move.l d0,(currdir_lock,a4)
CALL CurrentDir ;set current dir
move.l d0,(currdir_old,a4)
.no_currdir_old
lea (currdirtxt,pc),a0
move.l a0,d1
lea (vprintf_long1,pc),a0
move.l (16,a5),(a0)
move.l a0,d2
CALL VPrintf
.no_currdir_new
filenames_ok
;--------------------------------------
; open intermediate screen
move.l (dummyscreen,pc),d0
bne.b .no_dummy
lea (dummynewscreen,pc),a0
lea (screentaglist,pc),a1
CALLINT OpenScreenTagList
move.l d0,(dummyscreen,a4)
.no_dummy
;--------------------------------------
; open file
files_loop
clr (exit,a4)
moveq #1,d0
move.l d0,(scale_down_factor,a4)
lea (linefeedtxt,pc),a0
move.l a0,d1
CALLDOS PutStr
move.l (rtfilelist,pc),d0
beq.b .no_rtfiles
lea (rtfilelist_curr,pc),a0
move.l (a0),d0
beq ende
move.l d0,a1
move.l (a1),(a0) ;rtfl_Next
move.l (8,a1),d1 ;rtfl_Name
bra.b .open_file
.no_rtfiles
move.l (filenames_array,pc),a0
move.l (a0)+,d1
beq ende
move.l a0,(filenames_array,a4)
.open_file
move.l d1,(filename,a4)
lea (filenametxt,pc),a0
move.l a0,d1
lea (filename,pc),a0
move.l a0,d2
CALL VPrintf
move.l (filename,pc),d1
move.l #1005,d2 ;MODE_OLDFILE
CALL Open
move.l d0,(fh,a4)
bne.b .fileopen_ok
lea (fileopenerrtxt,pc),a0
move.l a0,d1
CALL PutStr
bra.b files_loop
.fileopen_ok
;--------------------------------------
; alloc JPEG decompress
lea (jph,pc),a0
lea (ajd_taglist,pc),a1
move.l (fh,pc),(4,a1)
move.l (jpegbase,pc),a6
jsr (-30,a6) ;AllocJPEGDecompressA()
tst.l d0
beq.b .ajd_ok
cmp.l #14,d0 ;JPGERR_NOTJPEG
bne.b .not_err14
lea (notjpegerrtxt,pc),a0
move.l a0,d1
CALLDOS PutStr
bra close_file
.not_err14
lea (allocjpegerrtxt,pc),a0
move.l a0,d1
lea (vprintf_long1,pc),a0
move.l a0,d2
move.l d0,(a0)
CALLDOS VPrintf
bra close_file
.ajd_ok
;--------------------------------------
; get JPEG info
retry_smaller
move.l (jph,pc),a0
lea (gji_taglist,pc),a1
move.l (scale_down_factor,pc),(gji_scale,a4)
move.l (jpegbase,pc),a6
jsr (-78,a6) ;GetJPEGInfoA()
tst.l d0
beq.b .gji_ok
lea (jpeginfoerrtxt,pc),a0
move.l a0,d1
lea (vprintf_long1,pc),a0
move.l a0,d2
move.l d0,(a0)
CALLDOS VPrintf
bra free_jph
.gji_ok
lea (jpeginfotxt,pc),a0
move.l a0,d1
lea (vprintf_long1,pc),a0
move.l a0,d2
move.l (width,pc),(a0)+
move.l (height,pc),(a0)
CALLDOS VPrintf
move.b (colourspace,pc),d1
subq.b #1,d1
bne.b .not_gray
lea (grayerrtxt,pc),a0
move.l a0,d1
CALL PutStr
bra free_jph
.not_gray
;--------------------------------------
; fit image to screen
move.l (fitscreen,pc),d0
beq.b .no_fitscreen
move.l (scale_down_factor,pc),d0
subq.l #1,d0
bne.b .no_fitscreen
move.l (width,pc),d0
move #352,d1 ;screen width (LoRes visible)
divu d1,d0
swap d0
move.l (height,pc),d2
move #280,d3 ;screen height
divu d3,d2
swap d2
cmp.l d0,d2
ble.b .max_d0
move.l d2,d0
move d3,d1
.max_d0
lsr #1,d1
sub d1,d0 ;remainder > 1/2 divisor ?
ble.b .quot_ok
add.l #$10000,d0 ;increment quotient
.quot_ok
swap d0
moveq #0,d1
move.b (.fit_table,pc,d0),d1
cmp.b #1,d1
beq.b .no_fitscreen
lea (scale_down_factor,pc),a0
move.l a0,d2
move.l d1,(a0)
lea (fitscreentxt,pc),a0
move.l a0,d1
CALLDOS VPrintf
bra retry_smaller
.fit_table
dc.b 1,1,2,4,4,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
.no_fitscreen
;--------------------------------------
; allocate chip memory
move.l (width,pc),d0
lsl.l #2,d0
add.l #63,d0
and.l #-64,d0
move.l d0,(width64,a4)
move.l (height,pc),d1
mulu d1,d0
lsr.l #3,d0
add.l #63,d0
and.l #-64,d0
move.l d0,(bitplanesize,a4)
move.l d0,d7
lsl.l #2,d0
add.l d7,d0
add.l d7,d0 ;*6
move.l d0,(chipmem_6size,a4)
move.l #$00050002,d1 ;MEMF_CHIP|MEMF_CLEAR|MEMF_REVERSE
CALLEXEC AllocMem
move.l d0,(chipmem_6pt,a4)
beq.b .no_chipmem
move.l d7,d0
add.l d0,d0 ;*2
move.l d0,(chipmem_2size,a4)
move.l #$00040002,d1 ;MEMF_CHIP|MEMF_REVERSE
CALL AllocMem
move.l d0,(chipmem_2pt,a4)
bne.b .chipmem_ok
.no_chipmem
lea (chipmem_6pt,pc),a0
move.l (a0),d0
beq.b .no_chip6
clr.l (a0)
move.l d0,a1
move.l (chipmem_6size,pc),d0
CALL FreeMem
.no_chip6
lea (chipmemerrtxt,pc),a0
move.l a0,d1
lea (vprintf_long1,pc),a0
move.l a0,d2
move.l (bitplanesize,pc),d0
lsr.l #7,d0
move.l d0,(a0)
CALLDOS VPrintf
lea (scale_down_factor,pc),a0
move.l (a0),d0
cmp.b #8,d0
bge free_chipmem
lsl.l #1,d0
move.l d0,(a0)
bra retry_smaller
.chipmem_ok
;--------------------------------------
; create bitmap structure
lea (bmap,pc),a0
move.l (width64,pc),d0
lsr.l #3,d0
move d0,(a0)+ ;BytesPerRow
move.l (height,pc),d0
move d0,(a0)+ ;Rows
clr.b (a0)+ ;Flags
move.b #8,(a0)+ ;Depth
clr (a0)+ ;pad
move.l (chipmem_6pt,pc),d0
move.l (bitplanesize,pc),d1
move.l d0,(a0)+ ;Plane 0
add.l d1,d0
move.l d0,(a0)+ ;Plane 1
add.l d1,d0
move.l d0,(a0)+ ;Plane 2
add.l d1,d0
move.l d0,(a0)+ ;Plane 3
add.l d1,d0
move.l d0,(a0)+ ;Plane 4
add.l d1,d0
move.l d0,(a0)+ ;Plane 5
move.l (chipmem_2pt,pc),d0
move.l d0,(a0)+ ;Plane 6
add.l d1,d0
move.l d0,(a0) ;Plane 7
;--------------------------------------
; open screen and window
lea (newscreen,pc),a0
move.l (width,pc),d0
lsl #2,d0
move d0,(4,a0)
move.l (height,pc),d0
move d0,(6,a0)
lea (screentaglist,pc),a1
CALLINT OpenScreenTagList
move.l d0,(screen,a4)
bne.b .screen_ok
.screrr lea (screenerrtxt,pc),a0
move.l a0,d1
CALLDOS PutStr
bra close_win
.screen_ok
lea (newwindow,pc),a0
move.l (screen,pc),a1
move.l a1,(30,a0)
move.l (12,a1),(4,a0)
lea (windowtaglist,pc),a1
CALL OpenWindowTagList
move.l d0,(window,a4)
beq.b .screrr
move.l d0,a5
CALLEXEC Disable
move.l (86,a5),a5 ;window.wd_UserPort
move.b #1,(14,a5) ;window.wd_UserPort->mp_Flags=PA_SOFTINT
lea (idcmp_softint,pc),a1
move.l a1,(16,a5) ;window.wd_UserPort->mp_SigTask/mp_SoftInt
CALL Enable
;--------------------------------------
; prepare HAM8 buffer
move.l (chipmem_2pt,pc),a0
move.l (bitplanesize,pc),d6
lsr.l #3,d6
move.l d6,d7
move.l #$77777777,